package com.dragon8869.myspringboot.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;

import java.util.HashMap;
import java.util.Map;

@Log4j2
public class JsonTest {

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();

        objectObjectHashMap.put(1, "1");
        objectObjectHashMap.put(2, "2");
        objectObjectHashMap.put(3, "3");
        objectObjectHashMap.put(4, "4");

        String json = om.writeValueAsString(objectObjectHashMap);
        log.info(json);

        /*CollectionType collectionType = om.getDeserializationConfig().getTypeFactory().constructCollectionType(Set.class, Integer.class);

        List<Integer> integers = om.readValue(json, new TypeReference<List<Integer>>() {
        });

        ObjectReader objectReader = om.readerForMapOf(Integer.class);*/
        Map<Integer, String> integerStringMap = om.readValue(json, new TypeReference<HashMap<Integer, String>>() {
        });
        log.info(integerStringMap);
    }
}
